
new;

Iv0=2000;
V0_sm=zeros(1,Iv0);

i=1;
do until i==Iv0+1;
V0_sm[1,i]=i;
i=i+1;
endo;

V0_sm=V0_sm/Iv0;



/* Oct. 7, 2003 */
/* Hong: Feb 7, 2004 */

/* simulation1_size program */
 
/* Sample size */
N=100;
n0=100;

/* Seed numbers */

iseed1=2555130;
iseed2=2660427;
iseed3=2552818;

/* USE ONLY ONE PRELIMINARY BANDWIDTH: Lamda=1/8 */

ALTER=1;
do until ALTER==1+1;

if ALTER==1;


Lamda1=1/6;
Lamda2=1/6;
LamdaA=1/6;
LamdaB=1/6;

elseif ALTER==2;


Lamda1=1/7;
Lamda2=1/7;
LamdaA=1/7;
LamdaB=1/7;

elseif ALTER==3; 



Lamda1=1/8;
Lamda2=1/8;
LamdaA=1/8;
LamdaB=1/8;


elseif ALTER==4;


Lamda1=1/9;
Lamda2=1/9;
LamdaA=1/9;
LamdaB=1/9;


elseif ALTER==5;


Lamda1=1/10;
Lamda2=1/10;
LamdaA=1/10;
LamdaB=1/10;

endif;

/* STANDARD QUARTIC KERNEL, with K(0)=0 to define leave-one-out estimators */


PROC k(u);
LOCAL Y;
Y=(15/16)*((1-u.*u)^2).*(abs(u).<=1.0).*(1-(u.==0));
/* NOTE: (1-u(.==0)) IS "LEAVE-ONE-OUT" */
RETP(Y);
ENDP;

/* Integral of u^L*k(u) from -b to 1 */

PROC WkL(l,b);
LOCAL Y;
Y=(15/16)*((1-(-b)^(l+1))/(l+1) - 2*(1-(-b)^(l+3))/(l+3) + (1-(-b)^(l+5))/(l+5) );
RETP (Y);
ENDP;

/* Integral of u^L*k(u) from -1 to b */
PROC WkR(l,b);
LOCAL Y;
Y=(15/16)*((b^(l+1)-(-1)^(l+1))/(l+1) - 2*(b^(l+3)-(-1)^(l+3))/(l+3) + (b^(l+5)-(-1)^(l+5))/(l+5) );
RETP (Y);
ENDP;

/* JACKKNIFE KERNEL */

PROC KbL(b,u); /* kernel for left boundary */
/* U may be a M x L MATRIX, b may be a 1 x L COLUMN VECTOR; FINAL OUTPUT IS a M x L MATRIX */
/* Or U may be M x 1, and b = 1 x L; the final output is a M x L matrix */
LOCAL r, a, Y;
a=2-b;

r= (WkL(1,b)./WkL(0,b))./(a.*WkL(1,b./a)./WkL(0,b./a)-WkL(1,b)./WkL(0,b)+(WkL(1,b).==0));
/* NOTE: (WkL(1,b).==0) PREVENTS THE CASE 0/0 */
Y=(1+r).*(K(u)./WkL(0,b))-(r./a).*(K(u./a)./WkL(0,b./a));

RETP(Y);
ENDP;


PROC KbR(b,u);  /*kernel for right boundary */
/* U may be a M x L MATRIX, b may be a 1 x L COLUMN VECTOR; FINAL OUTPUT IS a M x L MATRIX */
LOCAL r, a, Y;
a=2-b;

r= (WkR(1,b)./WkR(0,b))./(a.*WkR(1,b./a)./WkR(0,b./a)-WkR(1,b)./WkR(0,b)+(WkR(1,b).==0));
/* NOTE: (WkR(1,b).==0) PREVENTS THE CASE 0/0 */
Y=(1+r).*(K(u)./WkR(0,b))-(r./a).*(K(u./a)./WkR(0,b./a));

RETP(Y);
ENDP;



/* LOCATION DEPNDENT KERNEL */

PROC Kh(x,y,h);
LOCAL W,u;
u=(y-x)/h;

/* NOTE: y={Xs} TO BE SUMMED UP so that y is a cloumn vector, x={Xt} iS the points WHERE DENSITIES ARE ESTIAMTED so that x is a row vector */
W=(x.<h).*(1-x.>=h).*(1/h).*KbL((x/h),u) + (x.>=h).*(1-x.>=h).*(1/h).*K(u) +(x.>=h).* (1-x.<h).*(1/h).*KbR((1-x)/h,u); 
RETP(W);
ENDP;


/* ASYMPTOTIC VARIANCE OF TEST STATISTICS */


/* QUADTIC KERNEL k0(u) used for integration */

PROC k0(u);
LOCAL Y;
Y=(15/16)*((1-u.*u)^2).*(abs(u).<=1.0);
RETP(Y);
ENDP;

/* INTEGRATION PARAMETERS */

_INTREC=0;

Let U1={1,
              0};
_INTORD=40;

/* K0(u)^2 */

PROC K2(u);
LOCAL Y;
Y=K0(u).*K0(u);
RETP(Y);
ENDP;


/* First component of Variance */

/* THIS IS INTEGRAL OF k0(u)^2 */
/* 2 = symmetry */

SIGMA1=2*INTQUAD1( &K2,U1);

/* This has be compared with the closed form given as WK(1) below */


/* Second component of variance */

PROC SFUN2(u,v,w);
LOCAL Y;
Y=K0(u+v).*K0(v).*k0(u+w).*k0(w);
RETP(Y);
ENDP;

Let U3={1,
                -1};
_INTREC=0;
_INTORD=40;

/* INTEGRAL OF [INT k0(u+v)k0(v)]^2 */

Sigma2=INTQUAD3(&SFUN2, U3, U3, U3);

/* Third component of variance */

PROC SFUN12(u,v);
LOCAL Y;
Y=K0(u+v).*K0(u).*K0(v);
RETP(Y);
ENDP;


Let U4={1,
                -1};
_INTREC=0;
_INTORD=40;

/* INTEGRAL OF k0(u+v)k0(u)k0(v) */

Sigma12=INTQUAD2(&SFUN12, U4, U4);

/* VARIANCE RELATED TO BIVARIATE DENSITY ESTIMATION */

S2=8*Sigma1^2+2*Sigma2^2-8*Sigma12^2;

/* STANDARD DEVIATION */

SIGMA=sqrt(S2);


/* CENTERING CONSTANT */


/* THIS IS integral of k(u)^2 from -1 to b */

PROC Wk2(b);
LOCAL Y;
Y=(15/16)^2*(b-(4/3).*b^3+(6/5).*b^5-(4/7).*b^7+(1/9).*b^9 - ((-1)-(4/3)*(-1)^3+(6./5)*(-1)^5-(4/7)*(-1)^7+(1/9)*(-1)^9));
RETP(Y);
ENDP;

/* main part (first part) of centering constant */

Center_M1=Wk2(1); 


/* second part of centering constant due to boundary */

PROC Kb2(b,u);
/* We allow b = 1 x L and u = M x 1 */
LOCAL Y, r,a; 
a=2-b;
r=(WKL(1,b)./WKL(0,b))./(a.*WKL(1,b./a)./WKL(0,b./a)-WKL(1,b)./WKL(0,b)+(WKL(1,b).==0));
Y=(1+r).*K0(u)./WKL(0,b)-(r./a)*K0(u./a)./WKL(0,b./a);
Y=(Y^2).*(-b.<=u);
RETP(Y);
ENDP;


CENTER_M2=INTQUAD2(&Kb2,U1,U4);


/* The following used for data-driven bandwidths */

/* 2nd order derivative of k0(u) */

proc KDD(u);
local Y;
Y=(15/4)*(3*u.*u-1).*(abs(u).<=1).*(1-(u.==0));
retp(Y);
endp;


 /* SAMPLE-SPLITTING PROCEDURE FOR ROBINSON TEST */

/* Sample-Split Weighting FUNCTION : N-p x 1 Vector */
/* Below "p" IS the lag order, and r = nuisance parameter */

proc C(r,p);
local Y,j,j0;
Y=(1-r)*ones(N-p,1);

j=1;
do until j==N-p+1;

j0=(j-1)*p+j;
if j0 <= N-p;
Y[j0,1]=1+p*r;
endif;

j=j+1;
endo;

retp(Y);
endp;





/* Gaussian and Higher order kernels used in the original Robinson's test*/
/* They are not used in this simulation */

/* THIS IS THE GAUSSIAN KERNEL */

Const2=1/sqrt(2*pi);

PROC GK(u);
RETP(exp(-0.5*u.*u).*Const2.*(1-(u.==0)));
/* NOTE: (1-(u.==0)) IS LEAVE-ONE-OUT */
ENDP;

/* SECOND DERIVATIVE OF GK(u) */

PROC GKDD(u);
LOCAL Y;
Y=exp(-0.5*u.*u).*Const2.*(u.*u-1).*(1-(u.==0));
RETP(Y);
ENDP;

/* HIGHER ORDER KERNEL */

Const3=1/sqrt(8*pi);

PROC HK(u);
RETP((3-u.*u).*exp(-0.5*u.*u).*Const3.*(1-(u.==0)));
/* NOTE: (1-(u.==0)) IS LEAVE-ONE-OUT */
ENDP;


/* For Smoothed Bootstrap */


/* STANDARD QUARTIC KERNEL, with K(0)=0 to define leave-one-out estimators */


proc k_sm(u);
local Y;
Y=(15/16)*((1-u.*u)^2).*(abs(u).<=1.0);
retp(Y);
endp;

/* Integral of u^L*k(u) from -b to 1 */

proc WkL_sm(l,b);
local Y;
Y=(15/16)*((1-(-b)^(l+1))/(l+1) - 2*(1-(-b)^(l+3))/(l+3) + (1-(-b)^(l+5))/(l+5) );
retp (Y);
endp;

/* Integral of u^L*k(u) from -1 to b */
proc WkR_sm(l,b);
local Y;
Y=(15/16)*((b^(l+1)-(-1)^(l+1))/(l+1) - 2*(b^(l+3)-(-1)^(l+3))/(l+3) + (b^(l+5)-(-1)^(l+5))/(l+5) );
retp (Y);
endp;

/* JACKKNIFE KERNEL */

proc KbL_sm(b,u); /* kernel for left boundary */
/* U may be a M x L MATRIX, b may be a 1 x L COLUMN VECTOR; FINAL OUTPUT IS a M x L MATRIX */
/* Or U may be M x 1, and b = 1 x L; the final output is a M x L matrix */
local r, a, Y;
a=2-b;

r= (WkL_sm(1,b)./WkL_sm(0,b))./(a.*WkL_sm(1,b./a)./WkL_sm(0,b./a)-WkL_sm(1,b)./WkL_sm(0,b)+(WkL_sm(1,b).==0));
/* NOTE: (WkL(1,b).==0) PREVENTS THE CASE 0/0 */
Y=(1+r).*(K_sm(u)./WkL_sm(0,b))-(r./a).*(K_sm(u./a)./WkL_sm(0,b./a));

retp(Y);
endp;


proc KbR_sm(b,u);  /*kernel for right boundary */
/* U may be a M x L MATRIX, b may be a 1 x L COLUMN VECTOR; FINAL OUTPUT IS a M x L MATRIX */
local r, a, Y;
a=2-b;

r= (WkR_sm(1,b)./WkR_sm(0,b))./(a.*WkR_sm(1,b./a)./WkR_sm(0,b./a)-WkR_sm(1,b)./WkR_sm(0,b)+(WkR_sm(1,b).==0));
/* NOTE: (WkR(1,b).==0) PREVENTS THE CASE 0/0 */
Y=(1+r).*(K_sm(u)./WkR_sm(0,b))-(r./a).*(K_sm(u./a)./WkR_sm(0,b./a));

retp(Y);
endp;



/* LOCATION DEPNDENT KERNEL */

proc Kh_sm(x,y,h);
local W,u;
u=(y-x)/h;

/* NOTE: y={Xs} TO BE SUMMED UP so that y is a cloumn vector, x={Xt} iS the points WHERE DENSITIES ARE ESTIAMTED so that x is a row vector */
W=(x.<h).*(1-x.>=h).*(1/h).*KbL_sm((x/h),u) + (x.>=h).*(1-x.>=h).*(1/h).*K_sm(u) +(x.>=h).* (1-x.<h).*(1/h).*KbR_sm((1-x)/h,u); 
retp(W);
endp;


/* Maximum lag order */

Jmax=15;

/* BOOTSTRAP SAMPLE SIZE B0max */
B0max=100;

/* Simulation iteration number */

ITRmax=500;
ITR=1;
do until ITR==ITRmax+1;

/* Data generating process: DGP G */

e0=rndns(N+N0,1,iseed1);

X0=zeros(N+N0,1);

X0[1]=e0[1];
t=2;
do until t==N+N0+1;
X0[t]=0.8*(abs(X0[t-1]))^0.5+e0[t];
t=t+1;
endo;

X0=X0[N0+1:N0+N,1];


/* SCALE {X} ON SUPPORT [0,1] */

X0=1/(1+exp(-X0));

X0=(X0-minc(X0))/(maxc(X0)-minc(X0));

/* GENERATING BOOTSTRAP SAMPLES */

B0=0;
do until B0==B0max+1;

if B0==0;

/* ORIGINAL Estimated Standardized Residuals*/

X=X0;


/* BANDWIDTH SELECTION FOR ALL TESTS */
/* CROSS-VALIDATION */

/* PRELIMINARY BANDWIDTHS */

SDx=STDC(X); 
h10=SDx*N^(-Lamda1);
h20=SDx*N^(-Lamda2);

/* PRELIMINARY DENSITY/DERIVATIVE ESTIMATORS */
/* N-1 IS LEAVE-ONE-OUT */

Ghat0=sumc(Kh(X',X,h10))/(N-1);
GDDhat0=sumc((1./h20^3).*KDD((X'-X)./h20))/(N-1);

/* SUMMING OVER THE INTERIOR REGION ONLY  [h20, 1-h20]*/

D220=sumc((X.>=h20).*(X.<=1-h20).*(Ghat0.>0).*(GDDhat0./(Ghat0.*(Ghat0.>0)+(Ghat0.<=0)))^2)/sumc((X.>=h20).*(X.<=1-h20).*(Ghat0.>0));

/* PLUG-IN FORMULA */
/* FOR CONSTANTS, SEE HARDLE 1990, p.187 */

Hqcv=2.0362./(D220*N)^0.2;

/* USING SAME BANDWIDTH */

h=Hqcv;
h1=h;
h2=h;

/* smoothed density estimator, used to generate bootstrap samples */


/* Iv0 x1 density estimates */

g0_sm=meanc(Kh_sm(V0_sm,X,h));

/* Iv0 x 1 cdf estimates */

g0_cdf_sm=zeros(Iv0,1);

i=1;
do until i==Iv0+1;
if i==1;
g0_cdf_sm[i]=g0_sm[i];
else;
g0_cdf_sm[i]=g0_cdf_sm[i-1]+g0_sm[i];
endif;

i=i+1;
endo;

g0_cdf_sm=g0_cdf_sm/Iv0;

g0_cdf_sm=(g0_cdf_sm-minc(g0_cdf_sm))/(maxc(g0_cdf_sm)-minc(g0_cdf_sm));


/* Below are for BOOTSTRAP Residuals */

else;


/* Generate U[0,1] randam variables */

X=zeros(N,1);

IB=rndus(N,1,iseed2);

i=1;
do until i==N+1;

Y=1000*(g0_cdf_sm-IB[i]); 
Y=abs(Y);
Iy=indexcat(Y,minc(Y));
X[i]=v0_sm[1,Iy];
i=i+1;
endo;

/***************
/* this does not work */

/* smoothed marginal density function */

X=zeros(N,1);

i=1;
do until i==N+1;

eqsolveset;

proc G0_cdf(u);
local Y;
Y=g0_sm[1:ceil(Iv0*IB[i]),1];
Y=sumc(Y)/Iv0-IB[i];
retp(Y);
endp;

Start=IB[i];

{ X[i],retcode }=eqSolve(&G0_cdf,Start);

i~X[i]~IB[i];

i=i+1;
endo;

*****************************/



/* FOR BOOTSTRAP: corresponding to "If B0 >= 1" */
endif; 



/* SCALE {X} ON SUPPORT [0,1] */

X=(X-minc(X))/(maxc(X)-minc(X));


/********************************************************************

if B0==0; 

/* BANDWIDTH SELECTION FOR ALL TESTS */
/* CROSS-VALIDATION */

/* PRELIMINARY BANDWIDTHS */

SDx=STDC(X); 
h10=SDx*N^(-Lamda1);
h20=SDx*N^(-Lamda2);

/* PRELIMINARY DENSITY/DERIVATIVE ESTIMATORS */
/* N-1 IS LEAVE-ONE-OUT */

Ghat0=sumc(Kh(X',X,h10))/(N-1);
GDDhat0=sumc((1./h20^3).*KDD((X'-X)./h20))/(N-1);

/* SUMMING OVER THE INTERIOR REGION ONLY  [h20, 1-h20]*/

D220=sumc((X.>=h20).*(X.<=1-h20).*(Ghat0.>0).*(GDDhat0./(Ghat0.*(Ghat0.>0)+(Ghat0.<=0)))^2)/sumc((X.>=h20).*(X.<=1-h20).*(Ghat0.>0));

/* PLUG-IN FORMULA */
/* FOR CONSTANTS, SEE HARDLE 1990, p.187 */

Hqcv=2.0362./(D220*N)^0.2;

/* USING SAME BANDWIDTH */

h=Hqcv;
h1=h;
h2=h;

/* smoothed density estimator, used to generate bootstrap samples */

V0_sm=rndus(1,2000,iseed3);

/* 2000 x1 density estimates */

g0_sm=meanc(Kh_sm(V0_sm,X,h));


endif; 
/* for if B0==0 */

******************************************************************************/



/* COMPUTING TEST STATISTICS */

/* Ghat is N x 1 DENSITY VECTOR */
/* N-1 IS LEAVE-ONE-OUT Sample size */

Ghat=sumc(Kh(X',X,h1))/(N-1);


/* Centering Constant */

A0n=(1/h-2)*CENTER_M1+2*CENTER_M2;
D0n=(A0n-1)^2;

/* Second Version of Centering COnstant */

proc g00_den(x);
local Y;
Y=sumc(Kh(x',X0,h1))/(N-1)';
retp(Y);
endp;

/* This is the kernel density estimator using the original sample but evaluated at resample */

G00hat=g00_den(X);

A00n_est=sumc(Kh(X',X,h1)^2)/(N-1);
A0n_est=meanc((G00hat.>0).*A00n_est./(G00hat.*(G00hat.>0)+(G00hat.<=0))^2);

D0n_est=(A0n_est-1)^2;


/* We consider Jmax lags */

ST1=zeros(1,Jmax);
ST2=ST1;

Ihat=zeros(1,Jmax);

EM1=zeros(1,Jmax);
EM2=EM1;
EM3=EM1; 

j=1;
do until j==Jmax+1;

/* F1hat is (N-j) x 1 JOINT DENSITY VECTOR */
  
X1j=X[1:N-j,1];
X2j=X[j+1:N,1];

F1jhat=sumc(Kh(X1j',X1j,h2).*Kh(X2j',X2j,h2))/(N-j-1);

/* UNIVARIATE DENSITIES */

G1jhat=Ghat[1:N-j,1];
G2jhat=Ghat[j+1:N,1];

/* First Test */

/* Skaug-Tjostheim Test */

STj=sqrt(N-j).*meanc(F1jhat-G1jhat.*G2jhat);

/* Two Versions: Standardized vs. Nonstandardized */

ST1[1,j]=STj;
ST2[1,j]=STj;



/* ROBINSON WEIGHTS */
/* NOTE FOR ROBINSON TEST WE USE G2hat ONLY */

Crj=C(0.5,j).*(F1jhat.>0).*(G2jhat.>0);


/* SETTING NONPOSITIVES TO ZEROS: Needed for both the new test and Robinson's test */

G1jhat=G1jhat.*(G1jhat.>0)+(G1jhat.<=0);
G2jhat=G2jhat.*(G2jhat.>0)+(G2jhat.<=0);
F1jhat=F1jhat.*(F1jhat.>0)+(F1jhat.<=0);

 /* ENTROPY MEASURE */

Ihat[1,j]=sumc(ln(F1jhat)-ln(G1jhat)-ln(G2jhat));

/* WEIGHTING ENTROPY */

EMj=meanc(Crj.*(ln(F1jhat)-2*ln(G2jhat)));

EM1[1,j]=sqrt((N-j)/(j+1))*EMj;

EM2[1,j]=sqrt((N-j)/(j+1))*(EMj + 0.5*D0n/(N-j) );

EM3[1,j]=sqrt((N-j)/(j+1))*(EMj + 0.5*D0n_est/(N-j) );

j=j+1;
endo;


/* Skaug-Tjostheim Test Statistics */

/* asymptotic variance estimator */

SD_st=(stdc(Ghat))^2;

ST2=ST1;
ST1=ST1/SD_st;

/* NEW TEST STATISTIC */


Tn1=(2*h*Ihat+h*D0n)/SIGMA;

Tn2=(2*h*Ihat+h*D0n_est)/SIGMA;


/* ROBINSON'S TEST */


/* COMPUTING ASYMPTOTIC VARIANCE */
/* Setting nonpositive density estimates to ZERO in LOG*/

Ghat=Ghat.*(Ghat.>0)+(Ghat.<=0);

Vhat=STDC(ln(Ghat));

/* VERSION 1 */

Rn1=EM1/(0.5*sqrt(2)*Vhat);

/* ROBINSON TEST: VERSION 2*/

Rn2=EM2/(0.5*sqrt(2)*Vhat);

Rn3=EM3/(0.5*sqrt(2)*Vhat);


/* Portmanteau test */


ST1_pm=sqrt(5)*meanc(ST1[.,1:5]')~sqrt(10)*meanc(ST1[.,1:10]')~sqrt(15)*meanc(ST1[.,1:15]');
ST2_pm=sqrt(5)*meanc(ST2[.,1:5]')~sqrt(10)*meanc(ST2[.,1:10]')~sqrt(15)*meanc(ST2[.,1:15]');
Tn1_pm=sqrt(5)*meanc(Tn1[.,1:5]')~sqrt(10)*meanc(Tn1[.,1:10]')~sqrt(15)*meanc(Tn1[.,1:15]');
Tn2_pm=sqrt(5)*meanc(Tn2[.,1:5]')~sqrt(10)*meanc(Tn2[.,1:10]')~sqrt(15)*meanc(Tn2[.,1:15]');
Rn1_pm=sqrt(5)*meanc(Rn1[.,1:5]')~sqrt(10)*meanc(Rn1[.,1:10]')~sqrt(15)*meanc(Rn1[.,1:15]');
Rn2_pm=sqrt(5)*meanc(Rn2[.,1:5]')~sqrt(10)*meanc(Rn2[.,1:10]')~sqrt(15)*meanc(Rn2[.,1:15]');
Rn3_pm=sqrt(5)*meanc(Rn3[.,1:5]')~sqrt(10)*meanc(Rn3[.,1:10]')~sqrt(15)*meanc(Rn3[.,1:15]');


/* This is 1 x 5*(Jmax+3) vector */

STAT=(ST1~ST1_pm)~(ST2~ST2_pm)~(Tn1~Tn1_pm)~(Tn2~Tn2_pm)~(Rn1~Rn1_pm)~(Rn2~Rn2_pm)~(Rn3~Rn3_pm);


if B0==0;

/* ORIGINAL TEST STATISTICS */

STAT0=STAT;

endif;

/* BOOTSTRAP STATISTCS */

if B0==1;

STATcum=STAT;

elseif B0>1;

STATcum=STATcum|STAT;

endif;


B0=B0+1;
endo;

/* COMPUTE BOOSTRAP P-VALUES */
/* FIRST USE COUNT METHOD with Uncentered Test Statistics */

PV1=(STAT0-STATcum.<0);

PV1=meanc(PV1);

PV1=PV1';

/* Second: Count method with centered statistic */

PV2=(STAT0-(STATcum-STAT0).<0);

PV2=meanc(PV2);

PV2=PV2';

/* Third: Count method with self-centered statistic */

PV3=(STAT0-(STATcum-meanc(STATcum)').<0);

PV3=meanc(PV3);

PV3=PV3';

/* Fourth Method: SMOOTHED METHOD with Uncentered Statistic */

/* BOOTSTRAP SAMPLE OF SIZE B0max */

SDbst=STDC(STATcum);

SDbst=SDbst';

hbst=SDbst.*B0max^(-0.2);

PV4=(STAT0-STATcum)./hbst;

/* COMPUTE THE DENSITY OF BOOTSTRAP */

PV4=meanc(CDFNC(PV4));


PV4=PV4';

/* Fifth Method: SMOOTHED METHOD with Centered Statistic */

/* BOOTSTRAP SAMPLE OF SIZE B0max */

SDbst=STDC(STATcum-STAT0);

SDbst=SDbst';

hbst=SDbst.*B0max^(-0.2);

PV5=(STAT0-(STATcum-STAT0))./hbst;

/* COMPUTE THE DENSITY OF BOOTSTRAP */

PV5=meanc(CDFNC(PV5));

PV5=PV5';

/* Sixth Method: SMOOTHED METHOD with Self-Centered Statistic */

/* BOOTSTRAP SAMPLE OF SIZE B0max */

SDbst=STDC(STATcum-meanc(STATcum)');

SDbst=SDbst';

hbst=SDbst.*B0max^(-0.2);

PV6=(STAT0-(STATcum-meanc(STATcum)'))./hbst;

/* COMPUTE THE DENSITY OF BOOTSTRAP */

PV6=meanc(CDFNC(PV6));

PV6=PV6';


PV=PV1~PV2~PV3~PV4~PV5~PV6;

/* Seventh Method: Asymptotic P-value */

AsymPV=CDFNC(STAT0);

/* PLEASE CHANGE SUBDIRECTORY TO FIT YOUR PC */

output file=c:\gauss50\myout\white\size\smoothed\H100_100.out on;

/* THIS IS 1 x 1+(6+1+1)*(Jmax+3) VECTOR, where 6+1 are asymptotic abd bootstrap methods, 1 is statistic values */

ITR~PV~AsymPV~STAT0;

output off; 

ITR=ITR+1;
endo;

ALTER=ALTER+1;
endo;